﻿using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OpenXmlDocumentGenerator
{
    public static class ZipSerializer
    {

        public static void Serialize(object o, string path)
        {
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(o.GetType());
            MemoryStream ms = new MemoryStream();
            x.Serialize(ms, o);
            using (FileStream zipToOpen = new FileStream(path, FileMode.CreateNew))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
                {
                    ZipArchiveEntry readmeEntry = archive.CreateEntry("file.xml");
                    //readmeEntry.Open();
                    using (Stream writer = readmeEntry.Open())
                    {
                        ms.Position = 0;
                        ms.CopyTo(writer);
                        
                    }
                }
            }


        }
    }
}
